package com.alex.service;

import com.alex.dao.UserMapper;
import com.alex.pojo.User;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

@Service("userService")
@Transactional
public class UserServiceImpl implements UserService {

    private final UserMapper userMapper;
    public UserServiceImpl(UserMapper userMapper) {
        this.userMapper = userMapper;
    }

    @Override
    @Transactional(readOnly = true)
    public User getUser(int id) {
        return userMapper.getUser(id);
    }

    @Transactional(propagation = Propagation.REQUIRED)
    public boolean doSomething() {
        userMapper.addUser(new User("xxxx", "123"));
        userMapper.deleteUser(2);
        return true;
    }
}
